package com.youlai.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.system.common.result.PageResult;
import com.youlai.system.common.result.Result;
import com.youlai.system.pojo.form.StudentForm;
import com.youlai.system.pojo.form.TeacherForm;
import com.youlai.system.pojo.query.StudentPageQuery;
import com.youlai.system.pojo.query.TeacherPageQuery;
import com.youlai.system.pojo.vo.StudentPageVO;
import com.youlai.system.pojo.vo.TeacherPageVO;
import com.youlai.system.service.IExampleTeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhi
 * @since 2024-04-25
 */
@Tag(name = "09.教师接口")
@RestController
@RequestMapping("/api/v1/teachers")
@RequiredArgsConstructor
public class ExampleTeacherController {

    private final IExampleTeacherService iExampleTeacherService;

    @Operation(summary = "教师信息分页列表", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/page")
    public PageResult<TeacherPageVO> getTeacherPage(
            @ParameterObject TeacherPageQuery queryParams
    ){

        Page<TeacherPageVO> result = iExampleTeacherService.getTeacherPage(queryParams);

        return PageResult.success(result);


    }
    @Operation(summary = "教师信息表单数据", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/{id}/form")
    public Result<TeacherForm> getTeacherForm(
            @Parameter(description = "学生信息ID") @PathVariable Long id
    ){
        TeacherForm teacherForm = iExampleTeacherService.getTeacherForm(id);

        return Result.success(teacherForm);

    }

    @Operation(summary = "新增教师", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping
    public Result saveTeacher(
            @RequestBody TeacherForm teacherForm
    ){
        boolean result = iExampleTeacherService.saveTeacher(teacherForm);
        return Result.judge(result);
    }

    @Operation(summary = "修改教师", security = {@SecurityRequirement(name = "Authorization")})
    @PutMapping("/{id}")
    public Result updateTeacher(
            @PathVariable Long id,
            @RequestBody TeacherForm teacherForm

    ){
        boolean result = iExampleTeacherService.updateTeacher(id, teacherForm);

        return Result.judge(result);
    }

    @Operation(summary = "删除教师", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/{ids}")
    public Result deleteStudent(
            @Parameter(description ="教师信息ID，多个以英文逗号(,)拼接") @PathVariable String ids
    ){
        boolean result = iExampleTeacherService.deleteTeacher(ids);

        return Result.judge(result);
    }

}
